<script lang="ts" setup>
import useStore from '@/store';
import { useLazyData } from '@/utils/hooks';
// import { ref } from 'vue';
// import { useIntersectionObserver } from '@vueuse/core';
// import { ref } from 'vue';
import HomePanel from './HomePanel.vue'
import HomeSkeleton from './HomeSkeleton.vue';

const { home } = useStore()

// const target = ref(null)
// useLazyData(target, () => {
  
// })

// const target = useLazyData(() => {
//   // 自动调用: 当 target 出现在可视区后调用
//   home.getHomeNew()
// })

const target = useLazyData(() => home.getHomeNew())

// const target = ref(null)
// const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
//   if (isIntersecting) {
//     home.getHomeNew()
//     stop()
//   }
// })
</script>
<template>
  <div class="home-new">
    <HomePanel ref="target" title="新鲜好物" subtitle="新鲜出炉 品质靠谱">
      <template #right><XtxMore path="/" /></template>
      <transition name="fade">
        <!-- 面板内容 -->
        <ul class="goods-list" v-if="home.newGoodsList.length > 0">
          <li v-for="item in home.newGoodsList" :key="item.id">
            <RouterLink to="/">
              <img
                v-lazy="item.picture"
                alt=""
              />
              <p class="name ellipsis">{{ item.name }}</p>
              <p class="price">&yen;{{ item.price }}</p>
            </RouterLink>
          </li>
        </ul>
        <HomeSkeleton v-else />
      </transition>
    </HomePanel>
  </div>
</template>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>